<template>
  <ul class="m-tabs">
    <li v-for="(item, index) in tabTitle" :key="index" @click="check(index, item.menuItems)" :class="[cur == index ? 'active m-tabs-items' : 'm-tabs-items']">{{ item.name }}</li>
  </ul>
</template>

<script>
import { reactive, toRefs } from 'vue'

export default {
  name: 'Tab',
  props: {
    tabTitle: Array
  },
  setup(props, context) {
    const state = reactive({
      cur: 0
    })
    const check = (index, id) => {
      state.cur = index
      context.emit('activeId', id)
    }
    return {
      ...toRefs(state),
      check
    }
  }
}
</script>

<style lang="less">
.m-tabs {
  width: 300px;
  height: 32px;
  border: 1px solid #31c0fd;
  border-radius: 10px;
  overflow: hidden;
}
.m-tabs-items {
  position: relative;
  float: left;
  width: 33.333%;
  height: 32px;
  line-height: 32px;
  text-align: center;
  cursor: pointer;
}
.m-tabs-items:after {
  content: '';
  position: absolute;
  width: 1px;
  height: 20px;
  right: 0;
  top: 6px;
  background-color: #31c0fd;
}
.m-tabs-items:hover,
.m-tabs-items.active {
  color: #585858;
  background-color: #e3f6ff;
}
.m-tabs-items:last-child {
  border: none;
}
.m-tabs-items:last-child:after {
  display: none;
}
</style>
